package com.bluegalaxy.nhb.sntimer.timer;

import com.alibaba.fastjson.JSONObject;
import com.bluegalaxy.nhb.snservice.common.utils.AppConfig;

import com.bluegalaxy.nhb.snservice.common.utils.SpringContextUtil;
import com.bluegalaxy.nhb.snservice.service.ck.CkTestService;
import com.bluegalaxy.nhb.snservice.service.ck.UserGroupService;
import com.bluegalaxy.nhb.snservice.service.execute.ExecuteService;
import com.bluegalaxy.nhb.snservice.service.log.EdiLogService;
import com.bluegalaxy.nhb.snservice.support.cron.SNCron;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 *
 * @author:
 * @date: 2020/8/7
 * @time: 14:03
 * @description: To change this template use File | Settings | File Templates.
 */
public class DemoTimer extends SNCron {

    private Logger logger = LoggerFactory.getLogger(DemoTimer.class);

    public DemoTimer(String cronName, long timeout, boolean isExit) {
        super(cronName, timeout, isExit);
    }

    @Override
    public void cronThreadRun() throws Exception {
        logger.info("定时任务开始执行");
        this.doJob();
        logger.info("定时任务执行完成");
    }

    private void doJob(){
        System.out.println(AppConfig.getStringByProp("props/mail", "system.mail.host"));
//        EdiLogService ediLogService =  SpringContextUtil.getBean("EdiLogService");
        CkTestService ckTestService =  SpringContextUtil.getBean("CkTestService");
        logger.info("test结果："+ckTestService.selectCount());

        String table = "nhb_test_01";
        ExecuteService executeService = SpringContextUtil.getBean("ExecuteService");
        UserGroupService userGroupService = SpringContextUtil.getBean("UserGroupService");
//        logger.info("create结果："+executeService.createTable(table));
        List<String> list = new ArrayList<>();
        for(int i=100000;i<1000000;i++){
            list.add(i+"");
        }
        long start = System.currentTimeMillis();
        logger.info("insert结果："+userGroupService.insertBatch(table,list));
        long end = System.currentTimeMillis();
        logger.info("插入时间："+(end - start));


    }


}
